import type { ApiPagination, ApiPaginationParams } from '#types/utils'
import { formatDate } from '@vben/utils'
import { requestClient } from '../request'
import type { SaleCreateOrdersListParams, SaleCreateOrdersVo } from './model/creatorReceivable'

// 商品管理
export default class CreatorReceivableApi {
    static get inst() {
        return (
            CreatorReceivableApi._inst || (CreatorReceivableApi._inst = new CreatorReceivableApi())
        )
    }
    private static _inst: CreatorReceivableApi

    /**
     * 列表分页
     */
    getPageList(params: ApiPaginationParams<SaleCreateOrdersListParams>) {
        if (params.checkStartTime && params.checkEndTime) {
            params.checkStartTime = `${formatDate(params.checkStartTime, 'YYYY-MM-DD')} 00:00:00`
            params.checkEndTime = `${formatDate(params.checkEndTime, 'YYYY-MM-DD')} 23:59:59`
        }
        
        return requestClient.get<ApiPagination<SaleCreateOrdersVo>>('/broker/index', {
            params
        })
    }

    /**
     * 结算
     */
    settlement(params: {
        /**
         * v
         */
        closeStatus: number
        /**
         * 结算id列表
         */
        ids: Array<number | string>
    }) {
        return requestClient.put<null>('/broker/closeStatus', params)
    }
}
